/*
 * Main UI class for MyLatexEditor v1.0
 * Includes methods and variables for application user interface
 */

/*
 * myLatexEditor.java
 *
 * Created on 22.Mar.2009, 21:51:51
 */
package com.meraklisina.latexeditor;

import java.awt.ItemSelectable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilePermission;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.NumberFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Stack;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JToolBar.Separator;

import com.meraklisina.latexeditor.mdi.Common.CommonGuiListener;
import com.meraklisina.latexeditor.mdi.Common.FileOperations;
import com.meraklisina.latexeditor.mdi.Common.Tools;
import com.meraklisina.latexeditor.mdi.DialogActions.ActionOpen;
import com.meraklisina.latexeditor.mdi.FileFilters.FileFilterTEX;
import com.meraklisina.latexeditor.mdi.TextEditor.TextEditors;
import com.meraklisina.latexeditor.toolbarCustomize.CustomizeForm;
import com.meraklisina.latexeditor.util.ConfigurationGUI;
import com.meraklisina.latexeditor.util.LatexWordCounter;
import com.meraklisina.latexeditor.wizard.DynamicToolbarWizard;
import com.sun.pdfview.PDFFile;

/**
 *
 * @author kursattopcu
 */
public class ExeditorLatexEditor extends JFrame {

	private static final long serialVersionUID = 1L;

	public static ExeditorLatexEditor exeditorLatexEditor ;

	private static String currentFileName;
	private static String tempPdfFileName = "temp";
	private final static String tempStatic = "temp";
	private int tempCounter = 0;
	private PDFFile pdffile = null;
	private int LastPageDisplayed = 1;
	private int DocNumberOfPages = 0;
	//private String consoleText = "";

	/** Creates new form myLatexEditor */
	public ExeditorLatexEditor() {
		initComponents();
		try {
			CommonGuiListener.initListeners();
		} catch (Exception e) {
			e.printStackTrace();
			outputTextArea.append("Program initiation failed! Please restrart the program!");
		}
		createToolbarBtn.setVisible(false);
		Thread autoSaveThread=new Thread(new AutoSaveThread(this)); 
		autoSaveThread.start();
	}
	  
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		toolbarContextMenu = new JPopupMenu();
		customizeMenuItem = new JMenuItem();
		customizeDialog = new JDialog(this);
		customizeDialog.setModal(true);
		customizeDialog.setSize(430,300);
		customizeDialog.setResizable(false);
		customizeDialog.setTitle("Customize Toolbars");
		toolbarPanel = new JPanel();
		jToolBar1 = new JToolBar();
		newButton = new JButton();
		openButton = new JButton();
		saveButton = new JButton();
		jSeparator3 = new Separator();
		boldButton = new JButton();
		italicButton = new JButton();
		underlineButton = new JButton();
		jSeparator1 = new Separator();
		alignLeftButton = new JButton();
		alignCenterButton = new JButton();
		alignRightButton = new JButton();
		jSeparator2 = new Separator();
		cutButton = new JButton();
		copyButton = new JButton();
		pasteButton = new JButton();
		jSeparator6 = new Separator();
		commentOutBtn = new JButton();
		commentInBtn = new JButton();
		createToolbarBtn = new JButton();
		jSeparator7 = new Separator();
		jLabel1 = new JLabel();
		jComboBoxCovertTo = new JComboBox();
		convertToPdfButton = new JButton();
		hiddenLabel = new JLabel();
		btnPreview = new JButton();
		btnPreviewSelectedTex = new JButton();
		prevButton = new JButton();
		nextButton = new JButton();
		pagesTextField = new javax.swing.JTextField();
		jSplitPane1 = new ExtendedSplitPane();
		jSplitPane1.setDividerLocation(0.7);
		previewPanel1 = new PreviewPanel();
		jPanel1 = new JPanel();
		tab_Editors = new JTabbedPane();
		jPanel2 = new JPanel();
		jScrollPane1 = new JScrollPane();
		outputTextArea = new JTextArea();
		outputLabel = new JLabel();
		mainMenuBar = new JMenuBar();
		fileMenuExitItem = new JMenu();
		fileMenuNewItem = new JMenuItem();
		fileMenuOpen = new JMenuItem();
		fileMenuSave = new JMenuItem();
		fileMenuSaveAs = new JMenuItem();
		fileMenuCloseItem = new JMenuItem();
		fileMenuExit = new JMenuItem();
		jSeparator4 = new JSeparator();
		jSeparator5 = new JSeparator();
		editMenu = new JMenu();
		editMenuItemUndo = new JMenuItem();
		editMenuItemRedo = new JMenuItem();
		editMenuCopyItem = new JMenuItem();
		editMenuPasteItem = new JMenuItem();
		editMenuCutItem = new JMenuItem();
		findAndReplaceMenuItem = new JMenuItem();
		gotoLineMenuItem = new JMenuItem();
		setTemplateMenuItem = new JMenuItem();
		wordCountMenuItem = new JMenuItem();
		setMikTexPathMenuItem = new JMenuItem();
		toolBarMenu = new JMenu();
		helpMenu = new JMenu();  //TG 15-11-2009
		templateMenu = new JMenu(); //AE 23-11-2009
		tlist = new JMenuItem(); //AE 23-11-2009
		tlistDialog = new JDialog(this);
		tlistDialog.setModal(true);
		tlistDialog.setSize(430,300);
		tlistDialog.setResizable(false);
		tlistDialog.setTitle("Template List Toolbars");
		customize = new JMenuItem();
		create = new JMenuItem();
		//exportToolbar = new JMenuItem();
		//importToolbar = new JMenuItem();
		about = new JMenuItem(); //TG 15-11-2009
		help = new JMenuItem(); //TG 15-11-2009

		
		i18n.LoadLanguageFiles();
		
		
		toolbarContextMenu.setName("toolbarContextMenu"); // NOI18N

		customizeMenuItem.setLabel("Customize");
		customizeMenuItem.setName("customizeMenuItem"); // NOI18N
		customizeMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				customizeMenuItemActionPerformed(evt);
			}
		});

		customizeDialog.setName("customizeDialog"); // NOI18N

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("Exeditor LaTeX Editor v1.0");
		setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
		setName("mainFrame"); // NOI18N
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				formWindowClosing(evt);
			}
			public void windowOpened(WindowEvent evt) {
				formWindowOpened(evt);
			}
		});

		toolbarPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
		toolbarPanel.setAutoscrolls(true);
		toolbarPanel.setName("toolbarPanel"); // NOI18N
		toolbarPanel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent evt) {
				ExeditorLatexEditor.this.mouseClicked(evt);
			}
		});
		toolbarPanel.setLayout(new javax.swing.BoxLayout(toolbarPanel, javax.swing.BoxLayout.LINE_AXIS));

		jToolBar1.setRollover(true);
		jToolBar1.setName("jToolBar1"); // NOI18N

		newButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/page_white.png"))); // NOI18N
		newButton.setToolTipText("New");
		newButton.setFocusable(false);
		newButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		newButton.setName("newButton"); // NOI18N
		newButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		newButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				newButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(newButton);

		openButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/folder_magnify.png"))); // NOI18N
		openButton.setToolTipText("Open File...");
		openButton.setFocusable(false);
		openButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		openButton.setName("openButton"); // NOI18N
		openButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		openButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				openButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(openButton);

		saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/disk.png"))); // NOI18N
		saveButton.setToolTipText("Save");
		saveButton.setFocusable(false);
		saveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		saveButton.setName("saveButton"); // NOI18N
		saveButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		saveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				saveButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(saveButton);

		jSeparator3.setName("jSeparator3"); // NOI18N
		jToolBar1.add(jSeparator3);

		boldButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/text_bold.png"))); // NOI18N
		boldButton.setToolTipText("Bold");
		boldButton.setFocusable(false);
		boldButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		boldButton.setName("boldButton"); // NOI18N
		boldButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		boldButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				boldButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(boldButton);

		italicButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/text_italic.png"))); // NOI18N
		italicButton.setToolTipText("Italic");
		italicButton.setFocusable(false);
		italicButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		italicButton.setName("italicButton"); // NOI18N
		italicButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		italicButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				italicButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(italicButton);

		underlineButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/text_underline.png"))); // NOI18N
		underlineButton.setToolTipText("Underline");
		underlineButton.setFocusable(false);
		underlineButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		underlineButton.setName("underlineButton"); // NOI18N
		underlineButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		underlineButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				underlineButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(underlineButton);

		jSeparator1.setName("jSeparator1"); // NOI18N
		jToolBar1.add(jSeparator1);

		alignLeftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/text_align_left.png"))); // NOI18N
		alignLeftButton.setToolTipText("Align Left");
		alignLeftButton.setFocusable(false);
		alignLeftButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		alignLeftButton.setName("alignLeftButton"); // NOI18N
		alignLeftButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		alignLeftButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				alignLeftButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(alignLeftButton);

		alignCenterButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/text_align_center.png"))); // NOI18N
		alignCenterButton.setToolTipText("Align Center");
		alignCenterButton.setFocusable(false);
		alignCenterButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		alignCenterButton.setName("alignCenterButton"); // NOI18N
		alignCenterButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		alignCenterButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				alignCenterButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(alignCenterButton);

		alignRightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/text_align_right.png"))); // NOI18N
		alignRightButton.setToolTipText("Align Right");
		alignRightButton.setFocusable(false);
		alignRightButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		alignRightButton.setName("alignRightButton"); // NOI18N
		alignRightButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		alignRightButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				alignRightButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(alignRightButton);

		jSeparator2.setName("jSeparator2"); // NOI18N
		jToolBar1.add(jSeparator2);

		cutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/cut.png"))); // NOI18N
		cutButton.setToolTipText("Cut");
		cutButton.setFocusable(false);
		cutButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		cutButton.setName("cutButton"); // NOI18N
		cutButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		cutButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				cutButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(cutButton);

		copyButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/application_double.png"))); // NOI18N
		copyButton.setToolTipText("Copy");
		copyButton.setFocusable(false);
		copyButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		copyButton.setName("copyButton"); // NOI18N
		copyButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		copyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				copyButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(copyButton);

		pasteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/page_paste.png"))); // NOI18N
		pasteButton.setToolTipText("Paste");
		pasteButton.setFocusable(false);
		pasteButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		pasteButton.setName("pasteButton"); // NOI18N
		pasteButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		pasteButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				pasteButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(pasteButton);

		jSeparator6.setName("jSeparator6"); // NOI18N
		jToolBar1.add(jSeparator6);

		commentOutBtn.setText(i18n.GetMessage("commentOut"));
		commentOutBtn.setToolTipText(i18n.GetMessage("commentOut"));
		commentOutBtn.setFocusable(false);
		commentOutBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		commentOutBtn.setName(i18n.GetMessage("commentOut")); // NOI18N
		commentOutBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		commentOutBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				commentOutBtnActionPerformed(evt);
			}
		});
		jToolBar1.add(commentOutBtn);

		commentInBtn.setText(i18n.GetMessage("commentIn"));
		commentInBtn.setToolTipText(i18n.GetMessage("commentIn"));
		commentInBtn.setFocusable(false);
		commentInBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		commentInBtn.setName(i18n.GetMessage("commentIn")); // NOI18N
		commentInBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		commentInBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				commentInBtnActionPerformed(evt);
			}
		});
		jToolBar1.add(commentInBtn);

		createToolbarBtn.setText("Create Toolbar");
		createToolbarBtn.setToolTipText("Create Toolbar");
		createToolbarBtn.setFocusable(false);
		createToolbarBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		createToolbarBtn.setName("createToolbarBtn"); // NOI18N
		createToolbarBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		createToolbarBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				createToolbarBtnActionPerformed(evt);
			}
		});
		jToolBar1.add(createToolbarBtn);

		jSeparator7.setName("jSeparator7"); // NOI18N
		jToolBar1.add(jSeparator7);

		jLabel1.setText(i18n.GetMessage("convertTo"));
		jLabel1.setName("jLabel1"); // NOI18N
		jToolBar1.add(jLabel1);

		jComboBoxCovertTo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PDF", "DVI", "PS" }));
		jComboBoxCovertTo.setName("jComboBoxCovertTo"); // NOI18N
		jToolBar1.add(jComboBoxCovertTo);

		convertToPdfButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/building.png"))); // NOI18N
		convertToPdfButton.setToolTipText(i18n.GetMessage("convertTo"));
		convertToPdfButton.setFocusable(false);
		convertToPdfButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		convertToPdfButton.setName("convertToPdfButton"); // NOI18N
		convertToPdfButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		convertToPdfButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				convertToPdfButtonActionPerformed(evt);
			}
		});
		jToolBar1.add(convertToPdfButton);
		{
			ComboBoxModel navigationComboBoxModel = 
				new DefaultComboBoxModel(
						new String[] { i18n.GetMessage("currentDocument") });
			navigationComboBox = new JComboBox();
			jToolBar1.add(getNavigationComboBox());
			navigationComboBox.addItemListener(new ItemListener() {
				
				public void itemStateChanged(ItemEvent evt) {
				    
		            // Get the affected item
		            Object item = evt.getItem();
		    
		            if (evt.getStateChange() == ItemEvent.SELECTED) {
		                // Item was just selected
		            	NavigationComboPreparation ncp = new NavigationComboPreparation(tab_Editors); 
		            int pos = ncp.Navigate(item);
		            if(pos >= 0)
		            {
						getTextEditor().setCaretPosition(pos);
						getTextEditor().setSelectionStart(pos);
						getTextEditor().setFocusable(true);
		            }
		            } else if (evt.getStateChange() == ItemEvent.DESELECTED) {
		                // Item is no longer selected
		            }

				}
			});

			navigationComboBox.setModel(navigationComboBoxModel);
			
		}

		hiddenLabel.setName("hiddenLabel"); // NOI18N

		btnPreview.setText(i18n.GetMessage("preview"));
		btnPreview.setToolTipText(i18n.GetMessage("preview"));
		btnPreview.setName("btnPreview"); // NOI18N
		btnPreview.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				btnPreviewActionPerformed(evt);
			}
		});
		//TG needs some work on this feature.
		btnPreviewSelectedTex.setText(i18n.GetMessage("previewSelected"));
		btnPreviewSelectedTex.setToolTipText(i18n.GetMessage("previewSelected"));
		btnPreviewSelectedTex.setName("btnPreviewSelectedTex"); // NOI18N
		btnPreviewSelectedTex.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				btnPreviewSelectedTexActionPerformed(evt);
			}
		});

		prevButton.setText("<<");
		prevButton.setToolTipText("Previous");
		prevButton.setEnabled(false);
		prevButton.setName("prevButton"); // NOI18N
		prevButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				prevButtonActionPerformed(evt);
			}
		});

		nextButton.setText(">>");
		nextButton.setToolTipText("Next");
		nextButton.setEnabled(false);
		nextButton.setName("nextButton"); // NOI18N
		nextButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				nextButtonActionPerformed(evt);
			}
		});

		pagesTextField.setEditable(false);
		pagesTextField.setName("pagesTextField"); // NOI18N

		jSplitPane1.setDividerLocation(350);
		jSplitPane1.setName("jSplitPane1"); // NOI18N

		previewPanel1.setName("previewPanel1"); // NOI18N
		jSplitPane1.setRightComponent(previewPanel1);

		jPanel1.setName("jPanel1"); // NOI18N
		jPanel1.setLayout(new java.awt.BorderLayout());

		tab_Editors.setName("tab_Editors"); // NOI18N
		jPanel1.add(tab_Editors, java.awt.BorderLayout.CENTER);

		jPanel2.setName("jPanel2"); // NOI18N
		jPanel2.setLayout(new java.awt.BorderLayout());

		jScrollPane1.setName("jScrollPane1"); // NOI18N

		outputTextArea.setColumns(20);
		outputTextArea.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
		outputTextArea.setRows(5);
		outputTextArea.setDisabledTextColor(new java.awt.Color(255, 51, 51));
		outputTextArea.setEnabled(false);
		outputTextArea.setName("outputTextArea"); // NOI18N
		jScrollPane1.setViewportView(outputTextArea);

		jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

		outputLabel.setText("Output");
		outputLabel.setName("outputLabel"); // NOI18N
		jPanel2.add(outputLabel, java.awt.BorderLayout.PAGE_START);

		jPanel1.add(jPanel2, java.awt.BorderLayout.SOUTH);

		jSplitPane1.setLeftComponent(jPanel1);

		mainMenuBar.setName("jMenuBar1"); // NOI18N

		fileMenuExitItem.setText(i18n.GetMessage("new"));
		fileMenuExitItem.setName("fileMenuExitItem"); // NOI18N

		fileMenuNewItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
		fileMenuNewItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/page_white.png"))); // NOI18N
		fileMenuNewItem.setText(i18n.GetMessage("new"));
		
		fileMenuNewItem.setToolTipText(i18n.GetMessage("new"));
		fileMenuNewItem.setName("fileMenuNewItem"); // NOI18N
		fileMenuNewItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				fileMenuNewItemActionPerformed(evt);
			}
		});
		fileMenuExitItem.add(fileMenuNewItem);

		fileMenuOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
		fileMenuOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/folder_magnify.png"))); // NOI18N
		fileMenuOpen.setText(i18n.GetMessage("openFile"));
		fileMenuOpen.setToolTipText(i18n.GetMessage("openFile"));
		fileMenuOpen.setName("fileMenuOpen"); // NOI18N
		fileMenuOpen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				fileMenuOpenActionPerformed(evt);
			}
		});
		fileMenuExitItem.add(fileMenuOpen);

		fileMenuSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		fileMenuSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/disk.png"))); // NOI18N
		fileMenuSave.setText(i18n.GetMessage("save"));
		fileMenuSave.setToolTipText(i18n.GetMessage("new"));
		fileMenuSave.setName("fileMenuSave"); // NOI18N
		fileMenuSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				fileMenuSaveActionPerformed(evt);
			}
		});
		fileMenuExitItem.add(fileMenuSave);

		fileMenuSaveAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK));
		fileMenuSaveAs.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/saveAs.png")));
		fileMenuSaveAs.setText(i18n.GetMessage("saveAs"));
		fileMenuSaveAs.setToolTipText(i18n.GetMessage("saveAs"));
		fileMenuSaveAs.setName("fileMenuSaveAs"); // NOI18N
		fileMenuSaveAs.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				fileMenuSaveAsActionPerformed(evt);
			}
		});
		fileMenuExitItem.add(fileMenuSaveAs);
		
		fileMenuCloseItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK));
		fileMenuCloseItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/close.png")));
		fileMenuCloseItem.setText(i18n.GetMessage("closeCurrent"));
		fileMenuCloseItem.setToolTipText(i18n.GetMessage("closeCurrent"));
		fileMenuCloseItem.setName("fileMenuCloseItem"); // NOI18N
		fileMenuCloseItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				fileMenuCloseOpenTabActionPerformed(evt);
			}
		});
		fileMenuExitItem.add(fileMenuCloseItem);

		fileMenuExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK));
		fileMenuExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/door_out.png"))); // NOI18N
		fileMenuExit.setText(i18n.GetMessage("exit"));
		fileMenuExit.setToolTipText(i18n.GetMessage("exit"));
		fileMenuExit.setName("fileMenuExit"); // NOI18N
		fileMenuExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				fileMenuExitActionPerformed(evt);
			}
		});
		fileMenuExitItem.add(fileMenuExit);

		jSeparator4.setName("jSeparator4"); // NOI18N
		fileMenuExitItem.add(jSeparator4);

		jSeparator5.setName("jSeparator5"); // NOI18N
		fileMenuExitItem.add(jSeparator5);

		mainMenuBar.add(fileMenuExitItem);

		editMenu.setText(i18n.GetMessage("edit"));
		editMenu.setName("jMenu2"); // NOI18N

		editMenuItemUndo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK));
		editMenuItemUndo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/arrow_undo.png"))); // NOI18N
		editMenuItemUndo.setText(i18n.GetMessage("undo"));
		editMenuItemUndo.setToolTipText("Undo");
		editMenuItemUndo.setName("jMenuItemUndo"); // NOI18N
		editMenu.add(editMenuItemUndo);

		editMenuItemRedo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK));
		editMenuItemRedo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/arrow_redo.png"))); // NOI18N
		editMenuItemRedo.setText(i18n.GetMessage("redo"));
		editMenuItemRedo.setToolTipText("Redo");
		editMenuItemRedo.setName("editMenuItemRedo"); // NOI18N
		editMenu.add(editMenuItemRedo);

		editMenuCopyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
		editMenuCopyItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/application_double.png"))); // NOI18N
		editMenuCopyItem.setText(i18n.GetMessage("copy"));
		editMenuCopyItem.setToolTipText("Copy Selection");
		editMenuCopyItem.setName("editMenuCopyItem"); // NOI18N
		editMenuCopyItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				editMenuCopyItemActionPerformed(evt);
			}
		});
		editMenu.add(editMenuCopyItem);

		editMenuPasteItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK));
		editMenuPasteItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/page_paste.png"))); // NOI18N
		editMenuPasteItem.setText(i18n.GetMessage("paste"));
		editMenuPasteItem.setToolTipText("Paste");
		editMenuPasteItem.setName("editMenuPasteItem"); // NOI18N
		editMenuPasteItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				editMenuPasteItemActionPerformed(evt);
			}
		});
		editMenu.add(editMenuPasteItem);

		editMenuCutItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
		editMenuCutItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/cut.png"))); // NOI18N
		editMenuCutItem.setText(i18n.GetMessage("cut"));
		editMenuCutItem.setToolTipText("Cut Selection");
		editMenuCutItem.setName("editMenuCutItem"); // NOI18N
		editMenuCutItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				editMenuCutItemActionPerformed(evt);
			}
		});
		editMenu.add(editMenuCutItem);

		findAndReplaceMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
		findAndReplaceMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/findAndReplace.png"))); // NOI18N
		findAndReplaceMenuItem.setText(i18n.GetMessage("findreplace"));
		findAndReplaceMenuItem.setToolTipText("Find/Replace");
		findAndReplaceMenuItem.setName("FindReplaceMenuItem"); // NOI18N
		findAndReplaceMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				findReplaceMenuItemActionPerformed(evt);
			}
		});
		editMenu.add(findAndReplaceMenuItem);

		gotoLineMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK));
		gotoLineMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/map_go.png"))); // NOI18N
		gotoLineMenuItem.setText(i18n.GetMessage("gotoline"));
		gotoLineMenuItem.setToolTipText("Go to Line");
		gotoLineMenuItem.setName("GotoLineMenuItem"); // NOI18N
		gotoLineMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				gotoLineMenuItemActionPerformed(evt);
			}
		});
		editMenu.add(gotoLineMenuItem);
		
		wordCountMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK));
		wordCountMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/wordCount.png"))); // NOI18N
		wordCountMenuItem.setText(i18n.GetMessage("wordcount"));
		wordCountMenuItem.setToolTipText("Word Count");
		wordCountMenuItem.setName("WordCountMenuItem"); // NOI18N
		wordCountMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				wordCountMenuItemActionPerformed(evt);
			}
		});
		editMenu.add(wordCountMenuItem);
		
		setMikTexPathMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.CTRL_MASK));
		setMikTexPathMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/miktexPath.png"))); // NOI18N
		setMikTexPathMenuItem.setText(i18n.GetMessage("configuration"));
		setMikTexPathMenuItem.setToolTipText("Configuration");
		setMikTexPathMenuItem.setName("MikTeXPathMenuItem"); // NOI18N
		setMikTexPathMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				miktexPathMenuItemActionPerformed(evt);
			}
		});
		editMenu.add(setMikTexPathMenuItem);

		mainMenuBar.add(editMenu);

		toolBarMenu.setText(i18n.GetMessage("toolbar"));
		toolBarMenu.setName("jMenu1"); // NOI18N

		customize.setText(i18n.GetMessage("customize"));
		customize.setToolTipText("Customize Toolbar");
		customize.setName("customize"); // NOI18N
		customize.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				customizeMenuItemActionPerformed(evt);
			}
		});
		toolBarMenu.add(customize);

		create.setText(i18n.GetMessage("create"));
		create.setToolTipText("Create Toolbar");
		create.setName("create"); // NOI18N
		create.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				createToolbarBtnActionPerformed(evt);
			}
		});
		toolBarMenu.add(create);
		
		
		/* Toolbar import/export (erdem)  
		exportToolbar.setText("Export");
		exportToolbar.setToolTipText("ExportToolbar");
		exportToolbar.setName("export"); // NOI18N
		exportToolbar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				customizeMenuItemActionPerformed(evt);
			}
		});
		toolBarMenu.add(exportToolbar);
		
		importToolbar.setText("Import");
		importToolbar.setToolTipText("ImportToolbar");
		importToolbar.setName("import"); // NOI18N
		importToolbar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				customizeMenuItemActionPerformed(evt);
			}
		});
		toolBarMenu.add(importToolbar);
		*/
		
		customize.setText(i18n.GetMessage("customize"));
		customize.setToolTipText("Customize Toolbar");
		customize.setName("customize"); // NOI18N
		customize.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				customizeMenuItemActionPerformed(evt);
			}
		});
		toolBarMenu.add(customize);
		
		
		
		mainMenuBar.add(toolBarMenu);

		setJMenuBar(mainMenuBar);

		//Template Menu
		templateMenu.setText(i18n.GetMessage("templates"));
		templateMenu.setName(i18n.GetMessage("templates"));

//		tlist.setText("List");
//		tlist.setName("tlist");
//		tlist.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent evt) {
//				tlistMenuItemActionPerformed(evt);
//			}
//		});
//		templateMenu.add(tlist);
		setTemplateMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK));
		setTemplateMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/template.png"))); // NOI18N
		setTemplateMenuItem.setText(i18n.GetMessage("choosetemplate"));
		setTemplateMenuItem.setToolTipText("Choose Template");
		setTemplateMenuItem.setName("setTemplateMenuItem"); // NOI18N
		setTemplateMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				setTemplateMenuItemActionPerformed(evt);
			}
		});
		templateMenu.add(setTemplateMenuItem);

		mainMenuBar.add(templateMenu);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(layout.createSequentialGroup()
										.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE)
										.addContainerGap())
										.addGroup(layout.createSequentialGroup()
												.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(toolbarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE)
														.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE))
														.addComponent(hiddenLabel)
														.addContainerGap())
														.addGroup(layout.createSequentialGroup()
																.addComponent(btnPreview)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(btnPreviewSelectedTex)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(prevButton)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(pagesTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(nextButton))))
		);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(toolbarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(btnPreview)
								.addComponent(btnPreviewSelectedTex)
								.addComponent(prevButton, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(pagesTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(nextButton, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(2, 2, 2)
								.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(hiddenLabel)
										.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 514, javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(22, Short.MAX_VALUE))
		);

		//Help Menu
		helpMenu.setText(i18n.GetMessage("help"));
		helpMenu.setName(i18n.GetMessage("help"));

		about.setText(i18n.GetMessage("about"));
		about.setToolTipText("About");
		about.setName("About");
		about.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				helpInfoMenuItemActionPerformed(evt);
			}
		});
		helpMenu.add(about);

		help.setText(i18n.GetMessage("helpcontents"));
		help.setToolTipText("Help Contents");
		help.setName("help");
		help.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/meraklisina/latexeditor/resources/icons/help.png"))); // NOI18N
		help.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				helpMenuItemActionPerformed(evt);
			}
		});
		helpMenu.add(help);

		mainMenuBar.add(helpMenu);

		pack();
		setSize(1280,688);
		
	}// </editor-fold>//GEN-END:initComponents

	/**
	 * Load toolbars of the editor
	 */
	private void LoadToolbars() {
		String executionPath = System.getProperty("user.dir");
		executionPath = executionPath.replace("\\", "/") + "/AppConfig.xml";
		ToolBarHandler handler = ToolBarHandler.getHandler();
		handler.setContainer(toolbarPanel);
		//String url = getPathToJarfileDir(handler);
		try {
			//String temp = url + "/AppConfig.xml";
			handler.Generate(executionPath);//C:/Documents and Settings/kursattopcu/My Documents/NetBeansProjects/MyLatexEditor/src/mylatexeditor

			toolbarPanel.setVisible(true);
			outputTextArea.append("Toolbars successfully installed!\n");
			toolbarPanel.revalidate();
		} catch (Exception ex) {
			outputTextArea.append(ExceptionHandler.ProcessException(ex) + " PATH: " + executionPath);
		}
	}

	private void formWindowOpened(WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

		String executionPath = System.getProperty("user.dir");
		executionPath = executionPath.replace("\\", "/");
		Tools tool = new Tools(executionPath + "/"/*"/src/com/meraklisina/latexeditor/mdi/"*/, "");
		tool.InitializeTextEditors(this.tab_Editors);

		// add undo/redo to loaded text editors
		UndoRedo u = new UndoRedo();
		u.applyToTextEditors(this.tab_Editors, this.editMenuItemUndo, this.editMenuItemRedo);

		this.LoadToolbars();
		this.customizeForm =new CustomizeForm(this.customizeDialog);
		this.customizeDialog.getContentPane().add(customizeForm);
	}//GEN-LAST:event_formWindowOpened

	private void saveState() {
		TextEditors ClsTextEditor = new TextEditors();
		if (ClsTextEditor.WriteIntoXmlTextEditor()) {
			while (ClsTextEditor.getEditors().size() > 0) {
				ClsTextEditor.CloseTabAtDialog(this.tab_Editors, ClsTextEditor.GetLastChangedEditor(this.tab_Editors));
			}
		}

		ToolBarHandler tbh = ToolBarHandler.getHandler();
		tbh.serializeToolBars();
		String res =  tbh.getError();
		if(res.equals("") == false)
		{
			outputTextArea.append(res+"\n");
		}

	}

	/**
	 * Opens a new tab for the TEX file
	 */
	public void NewTab() {
		TextEditors ClsTextEditor = new TextEditors();
		ClsTextEditor.AddTab(tab_Editors);

		// apply undo/redo functionality to the new tab
		new UndoRedo(ClsTextEditor.GetJTextPane(tab_Editors), this.editMenuItemUndo, this.editMenuItemRedo);
	}

	/**
	 * Opens a file dialog
	 */
	public void OpenFile() {
		ActionOpen ClsActionOpen = new ActionOpen();
		ClsActionOpen.OpenDialog(tab_Editors);

		// apply undo/redo functionality to the new tab
		TextEditors ClsTextEditor = new TextEditors();
		new UndoRedo(ClsTextEditor.GetJTextPane(this.tab_Editors), this.editMenuItemUndo, this.editMenuItemRedo);
		NavigationComboPreparation ncp = new NavigationComboPreparation(this.tab_Editors);
		ComboBoxModel navigationComboBoxModel = 
			new DefaultComboBoxModel( ncp.ReadText()
					);

		navigationComboBox.setModel(navigationComboBoxModel);
	}

	/**
	 * Saves the Tex script to a file
	 * 
	 * @param IsSaveAs The save condition
	 * @return Operation completion succeeded or not
	 * 
	 */
	public boolean Save(boolean IsSaveAs) {
		boolean IsSaved;
		TextEditors clsTextEditor = new TextEditors();		
		//return clsTextEditor.SaveTab(tab_Editors, IsSaveAs);	
		//Ustteki satir yerine alttaki satirlar eklendi. AE. On the fly compile.
		//AE Start
		if (IsSaveAs) {
		    IsSaved = clsTextEditor.SaveTab(tab_Editors, IsSaveAs);
		    if (IsSaved) {
		    	outputTextArea.append("File successfully saved.\n");
		    }
		} else {
			IsSaved = clsTextEditor.SaveTabDirect(tab_Editors, IsSaveAs);
		}
		try {
			if (generatePdf("")) {
				DocNumberOfPages = Notify(tempPdfFileName);
			}
		} catch (FileNotFoundException ex) {
			Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
			outputTextArea.append(ex.toString()+"\n");
		} catch (IOException ex) {
			Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
			outputTextArea.append(ex.toString()+"\n");
		}
		return IsSaved;
		//AE Finish
	}

	/**
	 * Bold Toolbar Button Action Handler Method
	 * */
	private void boldButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_boldButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		String replacement = "\\textbf{" + selected + "}";
		replaceSelectedText(editors, replacement);
	}//GEN-LAST:event_boldButtonActionPerformed

	public static String getSelectedText(TextEditors editors){
		String selectedText = editors.GetText(tab_Editors);
		if(selectedText == null)
			selectedText = "";
		return selectedText;
	}

	public static void replaceSelectedText(TextEditors editors, String replacement){
		int tabIndex = tab_Editors.getSelectedIndex();
		editors.ReplaceSelectedText(tab_Editors, tabIndex, replacement);
	}
	/**
	 * File->Open Menu Item Action Handler
	 * */
	private void fileMenuOpenActionPerformed(ActionEvent evt) {//GEN-FIRST:event_fileMenuOpenActionPerformed
		//openButtonActionPerformed(evt);
		OpenFile();
	}//GEN-LAST:event_fileMenuOpenActionPerformed

	/**
	 * New File Toolbar Button Action Handler
	 * */
	private void newButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed

		NewTab();
	}//GEN-LAST:event_newButtonActionPerformed

	/**
	 * Save Toolbar Button Action Handler
	 * */
	private void saveButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed

		Save(false);
	}//GEN-LAST:event_saveButtonActionPerformed

	/**
	 * File->New Menu Item Action Handler
	 * */
	private void fileMenuNewItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_fileMenuNewItemActionPerformed
		//newButtonActionPerformed(evt);
		NewTab();
	}//GEN-LAST:event_fileMenuNewItemActionPerformed

	/**
	 * File->Save Menu Item Action Handler
	 * */
	private void fileMenuSaveActionPerformed(ActionEvent evt) {//GEN-FIRST:event_fileMenuSaveActionPerformed
		//fileMenuSaveActionPerformed(evt);
		Save(false);
	}//GEN-LAST:event_fileMenuSaveActionPerformed

	/**
	 * File->SaveAs Action Handler
	 * */
	private void fileMenuSaveAsActionPerformed(ActionEvent evt) {//GEN-FIRST:event_fileMenuSaveAsActionPerformed
		Save(true);
	}//GEN-LAST:event_fileMenuSaveAsActionPerformed

	private void fileMenuCloseOpenTabActionPerformed(ActionEvent evt) {//GEN-FIRST:event_fileMenuSaveAsActionPerformed
		// TG 29-11-2009
		TextEditors clsTextEditor = new TextEditors();
	
		int index = tab_Editors.getSelectedIndex();
		String filePath = clsTextEditor.GetRealPath(index);
		currentFileName = filePath;		
		int ret = JOptionPane.NO_OPTION;
		ret = JOptionPane.showConfirmDialog(this, "Save file: "+currentFileName+" ?", "Save", 
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
		if (ret == JOptionPane.YES_OPTION) {
			clsTextEditor.SaveTab(tab_Editors, false);
			clsTextEditor.CloseTab(tab_Editors);
		} else if(ret == JOptionPane.NO_OPTION || ret == JOptionPane.CANCEL_OPTION){
			clsTextEditor.CloseTab(tab_Editors);
		}		
	}	
	
	/**
	 * Italic Toolbar Button Action Handler
	 * */
	private void italicButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_italicButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		String replacement = "\\textit{" + selected + "}";
		replaceSelectedText(editors, replacement);
	}//GEN-LAST:event_italicButtonActionPerformed

	/**
	 * Underline Toolbar Button Action Handler Method
	 * */
	private void underlineButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_underlineButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		String replacement = "\\underline{" + selected + "}";
		replaceSelectedText(editors, replacement);
	}//GEN-LAST:event_underlineButtonActionPerformed

	/**
	 * Align Left Toolbar Button Action Handler Method
	 * */
	private void alignLeftButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_alignLeftButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		String replacement = "\\begin{flushleft}\n" + selected + "\n\\end{flushleft}";
		replaceSelectedText(editors, replacement);
	}//GEN-LAST:event_alignLeftButtonActionPerformed

	/*
	 * Align Center Toolbar Button Action Handler Method
	 * */
	private void alignCenterButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_alignCenterButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		String replacement = "\\begin{center}\n" + selected + "\n\\end{center}";
		replaceSelectedText(editors, replacement);
	}//GEN-LAST:event_alignCenterButtonActionPerformed

	/**
	 * Align Right Toolbar Button Action Handler Method
	 * */
	private void alignRightButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_alignRightButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		String replacement = "\\begin{flushright}\n" + selected + "\n\\end{flushright}";
		replaceSelectedText(editors, replacement);
	}//GEN-LAST:event_alignRightButtonActionPerformed

	/**
	 * Cut Toolbar Button Action Handler Method
	 * */
	private void cutButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_cutButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		String replacement = "";
		replaceSelectedText(editors, replacement);
		hiddenLabel.setVisible(false);
		hiddenLabel.setText(selected);
	}//GEN-LAST:event_cutButtonActionPerformed

	/**
	 * Copy Toolbar Button Action Handler Method
	 * */
	private void copyButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_copyButtonActionPerformed
		TextEditors editors = new TextEditors();
		String selected = getSelectedText(editors);
		hiddenLabel.setVisible(false);
		hiddenLabel.setText(selected);
	}//GEN-LAST:event_copyButtonActionPerformed

	/**
	 * Paste Toolbar Button Action Handler Method
	 * */
	private void pasteButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_pasteButtonActionPerformed
		TextEditors editors = new TextEditors();
		replaceSelectedText(editors, hiddenLabel.getText());
	}//GEN-LAST:event_pasteButtonActionPerformed

	/**
	 * Edit->Copy Menu Item Action Handler Method
	 * */
	private void editMenuCopyItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_editMenuCopyItemActionPerformed
		copyButtonActionPerformed(evt);
	}//GEN-LAST:event_editMenuCopyItemActionPerformed

	/**
	 * Edit->Paste Menu Item Action Handler Method
	 * */
	private void editMenuPasteItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_editMenuPasteItemActionPerformed
		pasteButtonActionPerformed(evt);
	}//GEN-LAST:event_editMenuPasteItemActionPerformed

	/**
	 * Open Button Action Handler Method
	 * */
	private void openButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed

		OpenFile();
	}//GEN-LAST:event_openButtonActionPerformed

	/**
	 * Bold Toolbar Button Action Handler Method
	 * */
	private void commentOutBtnActionPerformed(ActionEvent evt) {//GEN-FIRST:event_commentOutBtnActionPerformed
		TextEditors editors = new TextEditors();
		editors.CommentInOut(tab_Editors, true, "%");
	}//GEN-LAST:event_commentOutBtnActionPerformed

	/**
	 * File->Exit Menu Item Action Handler Method
	 * */
	private void fileMenuExitActionPerformed(ActionEvent evt) {//GEN-FIRST:event_fileMenuExitActionPerformed
		System.exit(0);
	}//GEN-LAST:event_fileMenuExitActionPerformed

	/**
	 * Build Toolbar Button Action Handler Method
	 * */
	private void convertToPdfButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_convertToPdfButtonActionPerformed
		//Once Save ediyor sonra istenen formata donusturuyor.TG
		// save the file first
		boolean saveCompleted = false;
		try{

			if(Save(false) == true)
			{
				saveCompleted =true;
				//	outputTextArea.append("The file is saved successfully: \n");
			}
		}catch(Exception exception){
			outputTextArea.append("The file cannot be saved!\nOperation cancelled!\n");
			//System.out.println("Save ederken olusan hata:"+exception.getMessage());
			saveCompleted = false;
		}
		if(saveCompleted)
		{
			try{
				String selectedBuilder = (String)jComboBoxCovertTo.getSelectedItem();
				MikTexStuff mikTex = new MikTexStuff();
				if(selectedBuilder.equalsIgnoreCase("DVI")){
					mikTex.buildProcess("latex.exe", outputTextArea, tab_Editors);
				}else if(selectedBuilder.equalsIgnoreCase("PDF")){
					//Burda OS windows ise pdflatex.exe, farkli bir OS ise ona gore bir converter lazim.TG
					mikTex.buildProcess("pdflatex.exe", outputTextArea, tab_Editors);
				}else if(selectedBuilder.equalsIgnoreCase("PS")){
					mikTex.buildProcess("dvips.exe", outputTextArea, tab_Editors);
				}

				TextEditors ClsTextEditor = new TextEditors();
				int index = tab_Editors.getSelectedIndex();
				JTextPane textPane = ClsTextEditor.GetJTextPane(tab_Editors);
				String filePath = ClsTextEditor.GetRealPath(index);

				int indexOfBSlash = filePath.lastIndexOf("\\");
				String pathDirectory =  filePath.substring(0, indexOfBSlash);
				String runningOperatingSystem = System.getProperty("os.name");

				/*Burada log file � okuyup hata arayacak. OK */
				String fileNameWoutExt = MikTexStuff.getFileNameWithoutExtension(filePath);
				String logFileNameWPath = "";
				if(runningOperatingSystem.contains("Windows")){
					outputTextArea.append("WINDOWS!\n");
					logFileNameWPath = pathDirectory + "\\" + fileNameWoutExt+".log" ;
				}else if(runningOperatingSystem.contains("Linux")){

					logFileNameWPath = pathDirectory + "/" + fileNameWoutExt+".log" ;
				}
				File logFile = new File(logFileNameWPath);
				String[] logMsg = new String[2];
				logMsg[0] = "";
				if(logFile.exists())
				{

					LogFileExaminer lfe = new LogFileExaminer(logFileNameWPath);	
					logMsg = lfe.ReadLogFile();

				}
				else
				{
					outputTextArea.append("Log file does not exist!Operation failed!\n");
					return;
				}

				if(logMsg[0].equals("") == false)
				{
					outputTextArea.append("There is an error on line "+ logMsg[1]+":\n"+logMsg[0]);
					return;
				}

				/*Burada log file � okuyup hata arayacak. SON OK*/



			}catch(Exception ee){
				outputTextArea.append("Compilation failed. Operation cannot be completed!\n");
			}     
		}
	}//GEN-LAST:event_convertToPdfButtonActionPerformed

	private void commentInBtnActionPerformed(ActionEvent evt) {//GEN-FIRST:event_commentInBtnActionPerformed
		TextEditors editors = new TextEditors();
		editors.CommentInOut(tab_Editors, false, "%");
	}//GEN-LAST:event_commentInBtnActionPerformed
    
	private void mouseClicked(MouseEvent evt) {//GEN-FIRST:event_mouseClicked
		if(evt.getButton()==MouseEvent.BUTTON3){
			mouseRightClicked(evt);
		}
	}//GEN-LAST:event_mouseClicked
	private void mouseRightClicked(MouseEvent evt) {
		// delete old ones
		this.toolbarContextMenu.removeAll();
		// add new toolbar menuitems
		ToolBarHandler handler=ToolBarHandler.getHandler();
		for(LatexToolBar tb:handler.getToolbars()){
			toolbarContextMenu.add(new LatexToolbarMenuItem(tb));
		}
		toolbarContextMenu.add(new JSeparator());
		toolbarContextMenu.add(this.customizeMenuItem);
		// display popupmenu
		this.toolbarContextMenu.show(this, evt.getXOnScreen(), evt.getYOnScreen());
	}
	private void editMenuCutItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_editMenuCutItemActionPerformed
		cutButtonActionPerformed(evt);
	}//GEN-LAST:event_editMenuCutItemActionPerformed

	private void formWindowClosing(WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
		saveState();
	}//GEN-LAST:event_formWindowClosing

	private void customizeMenuItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_customizeMenuItemActionPerformed
		this.customizeForm.reload();
		this.customizeDialog.setVisible(true);
	}//GEN-LAST:event_customizeMenuItemActionPerformed

	private void helpInfoMenuItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_customizeMenuItemActionPerformed
		//Message box acilacak versiyon numarasi yazilacak.
		//TG 15-11-2009
		//JOptionPane.showMessageDialog(helpMenu,"InfoMessage");
		JOptionPane.showMessageDialog
		(helpMenu, "ExEditor LaTeX Editor\nversion 1.1\n"
				+ "Copyleft 2009-  Under Development",
				"About", JOptionPane.INFORMATION_MESSAGE );
	}//

	private void helpMenuItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_customizeMenuItemActionPerformed
		//Messagebox acilacak help menusu gosterilecek. turkce menu yazilabilir.
		//TG 15-11-2009
		//JOptionPane.showMessageDialog(helpMenu,"Help Menu Message");
		try {
			String runningOperatingSystem = System.getProperty("os.name");
			if(runningOperatingSystem.contains("Windows"))
			{
				String executionPath = System.getProperty("user.dir");
				executionPath = executionPath.replace("\\", "/") + "/Exeditor.chm";
				Runtime.getRuntime().exec("hh.exe \""+executionPath+"\"");
			}
			else if(runningOperatingSystem.contains("Windows"))
			{
				String executionPath = System.getProperty("user.dir");
				executionPath = executionPath.replace("\\", "/") + "/Exeditor.chm";
				Runtime.getRuntime().exec("/usr/bin/xchm \""+executionPath+"\"");
			}
				
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


	//Template Begin.AE
	private void tlistMenuItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_tchooseMenuItemActionPerformed
		this.customizeForm.reload();
		this.tlistDialog.setVisible(true);
	}
	//Template End.AE

	private void findReplaceMenuItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_FindReplaceMenuItemActionPerformed
		JDialog dialog=new JDialog();
		FindReplace findReplace=new FindReplace(dialog, this.tab_Editors);
		dialog.getContentPane().add(findReplace);

		dialog.setTitle("Find/Replace");
		dialog.setSize(400, 175);
		dialog.setLocation((int)this.getLocation().getX() + 200, (int)this.getLocation().getY() + 200);
		dialog.setResizable(false);
		dialog.setModal(true);
		dialog.setVisible(true);

	}//GEN-LAST:event_FindReplaceMenuItemActionPerformed
	
	private void gotoLineMenuItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_gotoLineMenuItemActionPerformed
		JDialog dialog=new JDialog();
		GotoLine gotoLine =new GotoLine(dialog, this.tab_Editors);
		dialog.getContentPane().add(gotoLine);

		dialog.setTitle("Go to Line");
		dialog.setSize(400, 100);
		dialog.setLocation((int)this.getLocation().getX() + 200, (int)this.getLocation().getY() + 200);
		dialog.setResizable(false);
		dialog.setModal(true);
		dialog.setVisible(true);

	}//GEN-LAST:event_gotoLineMenuItemActionPerformed
	
	private void setTemplateMenuItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_FindReplaceMenuItemActionPerformed
		
		//get list of templates from the specified location. (traverse templates directory and find all the files ending with .tex extension)
		//choose the selected template ()
		//open the template in the editor pane
		TextEditors clsTextEditor = new TextEditors();
		FileOperations ClsFile = new FileOperations();
		 JFileChooser fileChooser = new JFileChooser();
	     File lastOpen = new File("templates\\");
         fileChooser.setCurrentDirectory(lastOpen);
         fileChooser.setDialogTitle("Open");
         fileChooser.setFileFilter(new FileFilterTEX());
         int returnValue = fileChooser.showOpenDialog(null);
         if (returnValue == JFileChooser.APPROVE_OPTION)
         {
               File selectedFile = fileChooser.getSelectedFile();
               Tools.setLastOpenedDirectory(fileChooser.getSelectedFile().getPath());

               boolean IsFileExist = false;

               for(TextEditors editor : clsTextEditor.getEditors())
               {
                   if(editor.getRealPath().equals(selectedFile.getPath()))
                   {
                       JOptionPane.showMessageDialog(null,"This file is already opened.","File Warning",JOptionPane.WARNING_MESSAGE);
                       IsFileExist = true;
                       break;
                   }

               }

               if(!IsFileExist)
               {
                   if(clsTextEditor.GetScrapPath(tab_Editors.getSelectedIndex()).isEmpty() && clsTextEditor.GetRealPath(tab_Editors.getSelectedIndex()).isEmpty() && !clsTextEditor.GetIsTextChanged(tab_Editors.getSelectedIndex()))
                   {
                       ClsFile.ReadFileWriteTextField(clsTextEditor.GetJTextPaneAt(tab_Editors, tab_Editors.getSelectedIndex()), selectedFile);
                       clsTextEditor.SetRealPath(tab_Editors.getSelectedIndex(), selectedFile.getPath());
                       tab_Editors.setTitleAt(tab_Editors.getSelectedIndex(), selectedFile.getName());

                   }
                   else
                   {
                	   clsTextEditor.AddTab(tab_Editors, false, "", selectedFile.getPath(), selectedFile);
                   }
               }
               //SetTextChange(Form, false);
         }

	}//GEN-LAST:event_FindReplaceMenuItemActionPerformed
	
	//count number of words in the current tex file
	private void wordCountMenuItemActionPerformed(ActionEvent actionEvent) {
		JDialog dialog=new JDialog();
		TextEditors textEditors  = new TextEditors();
		int index = tab_Editors.getSelectedIndex();
		String pathOfCurrentTexFile = textEditors.GetRealPath(index);
		if(pathOfCurrentTexFile !=null && !pathOfCurrentTexFile.equals("")){
			LatexWordCounter latexWordCounter = new LatexWordCounter(pathOfCurrentTexFile,dialog, tab_Editors);
			dialog.getContentPane().add(latexWordCounter);

			dialog.setTitle("Count Words");
			dialog.setSize(200, 100);
			dialog.setLocation((int)this.getLocation().getX() + 200, (int)this.getLocation().getY() + 200);
			dialog.setResizable(false);
			dialog.setModal(true);
			dialog.setVisible(true);
		}
		else {
			//Display warning popup for there is no opened tex file in the editor.
			JOptionPane.showMessageDialog
			(wordCountMenuItem, "Please open a TeX file to count number of words in it!",
					"Warning",JOptionPane.WARNING_MESSAGE );
		}
	}
	
	//count number of words in the current tex file
	private void miktexPathMenuItemActionPerformed(ActionEvent actionEvent) {
		JDialog dialog=new JDialog();
		ConfigurationGUI configurationGUI = new ConfigurationGUI(MikTexStuff.getMikTexPath(),dialog, tab_Editors);
		
		dialog.getContentPane().add(configurationGUI);
		
		dialog.setTitle("Configuration");
		dialog.setSize(500, 300);
		dialog.setLocation((int)this.getLocation().getX() + 200, (int)this.getLocation().getY() + 200);
		dialog.setResizable(false);
		dialog.setModal(true);
		dialog.setVisible(true);
		//Implementation will be added. TG 30-11-2009
		
//		GroupLayout layout = new GroupLayout(this);
//		this.setLayout(layout);

	}
	/**
	 * Generates the PDF file of the currently selected tab document.
	 * @return Generation completed or not
	 * @throws java.io.FileNotFoundException
	 * @throws java.io.IOException
	 */
	private boolean generatePdf(String previewDocumentContent) throws FileNotFoundException, IOException {
		NavigationComboPreparation ncp = new NavigationComboPreparation(this.tab_Editors);
		ComboBoxModel navigationComboBoxModel = 
			new DefaultComboBoxModel( ncp.ReadText()
					);

		navigationComboBox.setModel(navigationComboBoxModel);
		
		TextEditors ClsTextEditor = new TextEditors();
		int index = tab_Editors.getSelectedIndex();
		String filePath = "";
		Process proc = null;
		ProcessBuilder pbuilder = new ProcessBuilder();
		String runningOperatingSystem = System.getProperty("os.name");
		File newTempTexFile = null;
		if(previewDocumentContent != null && !previewDocumentContent.equals("")){
			if(runningOperatingSystem.contains("Windows")){
				newTempTexFile = new File("tempPreview\\temp.tex");
			}
			else if (runningOperatingSystem.contains("Linux")){
				newTempTexFile = new File("tempPreview/temp.tex");
			}
			else if (runningOperatingSystem.contains("Mac")){
				newTempTexFile = new File("tempPreview/temp.tex");
			}
			try{
				OutputStream out = new FileOutputStream(newTempTexFile);
				byte[] buff = previewDocumentContent.getBytes();
				out.write(buff, 0, buff.length);
				filePath = newTempTexFile.getAbsolutePath();
				currentFileName = filePath;
				newTempTexFile.setWritable(true, true);
				FilePermission filePermission = new FilePermission(currentFileName,"write");
			}catch(Exception ex){
				outputTextArea.append(ex.toString()+"\n");
			}
		} else {
			filePath = ClsTextEditor.GetRealPath(index);
			currentFileName = filePath;
		}
		pbuilder.directory(new File(getFilePath(currentFileName)));
		
		BufferedReader input;
		//bos tmp bi pdffile ver
		//changeDisplay();		

		if (!new File(currentFileName).exists()) {
			return false;
		}
		try {
			String[] ex = null;
			//if(previewDocumentContent == null || previewDocumentContent.equals("")){
				ex = new String[]{"pdflatex", "-halt-on-error", "-interaction", "nonstopmode", "-output-directory", getFilePath(currentFileName), currentFileName};
			//} 
//			else {
//				ex = new String[]{"pdflatex", "-halt-on-error", "-interaction", "nonstopmode", "-output-directory", getFilePath(newTempTexFile.getAbsolutePath()), newTempTexFile.getAbsolutePath()};
//			}
			pbuilder.command(ex);
			proc = pbuilder.start();
			String line;

			input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
			while ((line = input.readLine()) != null) {
				 //outputTextArea.append("[output] " + line + "\n");
			}
			input.close();

			input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
			while ((line = input.readLine()) != null) {
				outputTextArea.append("[errors] " + line + "\n");
			}
			input.close();

			int indexOfBSlash = 0;
			if(runningOperatingSystem.contains("Windows")){
				indexOfBSlash = currentFileName.lastIndexOf("\\");
			}
			else if (runningOperatingSystem.contains("Linux")){
				indexOfBSlash = currentFileName.lastIndexOf("/");
			}
			String pathDirectory = "";
			File oldTempFile = null;
			//Burda preview yaparken exception veriyor.TG
			if(runningOperatingSystem.contains("Windows")){
				if(indexOfBSlash != -1){ //OS windows ise calisiyor. burda check etmek lazim OS nin win ya ubuntu oldugunu.TG
					if(previewDocumentContent != null && !previewDocumentContent.equals("")){
				    	//Runtime.getRuntime().exec("cmd /c start AcroRd32.exe "+newExportedPDFFile);
				    }
					pathDirectory = currentFileName.substring(0, indexOfBSlash);
					oldTempFile = new File(pathDirectory + "\\" + tempPdfFileName);
				    String currentExportedPDFFileName = currentFileName.replace("tex", "pdf");
				    if(previewDocumentContent != null && !previewDocumentContent.equals("")){
				    	//Runtime.getRuntime().exec("cmd /c start AcroRd32.exe "+newExportedPDFFile);
				    } else {
				    	//Runtime.getRuntime().exec("cmd /c start AcroRd32.exe "+currentExportedPDFFileName);
				    }
				}
			} else if(runningOperatingSystem.contains("Linux")){
				pathDirectory = currentFileName.substring(0, indexOfBSlash);
				oldTempFile = new File(pathDirectory + "/" + tempPdfFileName);
			}

			/*Burada log file icini okuyup hata arayacak. OK */

			String fileNameWoutExt = MikTexStuff.getFileNameWithoutExtension(currentFileName);
			String logFileNameWPath = "";
			if(runningOperatingSystem.contains("Windows")){
				logFileNameWPath = pathDirectory + "\\" + fileNameWoutExt+".log" ;
			}else if(runningOperatingSystem.contains("Linux")){
				logFileNameWPath = pathDirectory + "/" + fileNameWoutExt+".log" ;
			}
			File logFile = new File(logFileNameWPath);
			String[] logMsg = new String[2];
			logMsg[0] = "";
			if(logFile.exists())
			{
				LogFileExaminer lfe = new LogFileExaminer(logFileNameWPath);	
				logMsg = lfe.ReadLogFile();
			}

			/*Burada log file icini okuyup hata arayacak. SON OK*/

			if(logMsg[0].equals(""))
			{
				tempPdfFileName = tempStatic + Integer.toString(tempCounter);
				tempCounter++;

				copyToTempPdf(currentFileName, tempPdfFileName,indexOfBSlash,runningOperatingSystem);

				if(oldTempFile.exists()){
					try{
						oldTempFile.deleteOnExit();
					}
					catch(SecurityException sec){
						outputTextArea.append("Temp file could not be deleted!\n");
					}
					catch(Exception exs){
						outputTextArea.append(exs.getMessage()+"\n");
					}
				}
				int value = proc.waitFor();
				if (value != 0) {
					return false;
				}
				return true;
			}
			else
			{
				outputTextArea.append("There is an error on line "+ logMsg[1]+":\n"+logMsg[0]);
				int ind = logMsg[0].indexOf(".");
				ind = ind + 1;
				JOptionPane.showMessageDialog(this, logMsg[0].substring(0, ind));
				return false;	
			}

		} catch (IOException exception) {
			outputTextArea.append("pdflatex: IOException " + exception.getMessage()+ exception.toString()+"\n");
			return false;
		}
		catch (Throwable e) {
			outputTextArea.append("pdflatex: Command not found " + e.getMessage()+ e.toString()+"\n");
			return false;
		}
		finally {
			if (proc != null) {
				try {
					proc.getInputStream().close();
					proc.getOutputStream().close();
					proc.getErrorStream().close();
					proc.destroy();
				} catch (IOException ex) {
					ex.printStackTrace();
					outputTextArea.append(ex.toString()+"\n");
				}
			}
		}
	}

	/**
	 * Copies the content of TEX file to a new file
	 * @param pathOriginal the path of the TEX file
	 * @param tempFileName name of the file destination file
	 * @throws java.io.IOException
	 */
	public boolean copyToTempPdf(String pathOriginal, String tempFileName, int indexOfBSlashFromCaller, String OS) throws IOException{
		//metoda int indexOfBSlashFromCaller parametresi eklendi.
		//changeDisplay();
		//int indexOfBSlash = pathOriginal.lastIndexOf("\\");
		//int indexOfBSlash = pathOriginal.lastIndexOf("\\"); deneme amacli iptal edildi.TG
		String pathDirectory = pathOriginal.substring(0, indexOfBSlashFromCaller);
		String pathOriginalPdf = pdfExt(pathOriginal);
		String pathTemp = "";
		if(OS.contains("Windows")){
			pathTemp = pathDirectory + "\\" + tempFileName;
		} else if(OS.contains("Linux")){
			pathTemp = pathDirectory + "/" + tempFileName;
		}
		File fileOriginal = new File(pathOriginalPdf);
		File fileTemp = new File(pathTemp);

		try {
			InputStream in = new FileInputStream(fileOriginal);
			OutputStream out = new FileOutputStream(fileTemp);
			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0){
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
			return true;
		} catch (FileNotFoundException ex) {
			Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
			outputTextArea.append(pathOriginal + "could not be found. Operation is terminated!\n");
			return false;
			// System.out.println(ex.getMessage());
		}
		finally
		{
			fileTemp.deleteOnExit();
		}
	}
	
	/**
     * Copies the content of tex file to a new file
     * @param pathOriginal the path of the tex file
     * @param tempFileName name of the file destination file
     * @throws java.io.IOException
     */
    public void copyToTempPdf(String pathOriginal, String tempFileName) throws IOException{
        //changeDisplay();
        int indexOfBSlash = pathOriginal.lastIndexOf("\\");
        String pathDirectory;
        if(indexOfBSlash >= 0)
        {
        	pathDirectory = pathOriginal.substring(0, indexOfBSlash);
        }
        else
        {
        	pathDirectory = getFilePath(currentFileName);
        }
        String pathOriginalPdf = pdfExt(pathOriginal);
        String pathTemp;
        if(indexOfBSlash >= 0)
        {
        	pathTemp = pathDirectory + "\\" + tempFileName;
        }
        else
        {
        	pathTemp = pathDirectory = getFilePath(currentFileName) + "/" + tempFileName;
        }
        File fileOriginal = new File(pathOriginalPdf);
        File fileTemp = new File(pathTemp);

        try {
            InputStream in = new FileInputStream(fileOriginal);
            OutputStream out = new FileOutputStream(fileTemp);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0){
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println(ex.getMessage());
        }
        fileTemp.deleteOnExit();
    }

	/**
	 * Returns the PDF extension string of the TEX file
	 * @param texFilename name of the TEX file
	 * @return   string with PDF extension
	 */
	private String pdfExt(String texFilename) {
		return texFilename.replaceFirst("[.][a-zA-Z]+$", ".pdf");
	}

	/**
	 * Changes the preview to the given TEX file's PDF
	 * @param texFileName TEX file name (without the path) that will be displayed on preview panel.
	 * @throws java.io.FileNotFoundException
	 * @throws java.io.IOException
	 */
	public void changeDisplay(String texFileName) throws FileNotFoundException, IOException{
		int indexOfBSlash = currentFileName.lastIndexOf("\\");
		String pathDirectory = currentFileName.substring(0, indexOfBSlash);
		File fileTex = new File(pathDirectory + "\\" + texFileName);
		//File file = new File(pdfExt("C:\\Documents and Settings\\vedat.ekiz\\Desktop\\yyyy\\tmp.tex"));
		File filePdf = new File(pdfExt(fileTex.getAbsolutePath()));
		try{
			OutputStream out = new FileOutputStream(fileTex);
			String def = "\\documentclass{article}\n\\begin{document}\nERROR\n\\end{document}";
			byte[] buff = def.getBytes();
			out.write(buff, 0, buff.length);
		}catch(Exception ex){
			outputTextArea.append(ex.toString()+"\n");
		}
		RandomAccessFile raf = new RandomAccessFile(filePdf, "r");
		FileChannel channel = raf.getChannel();
		ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
		pdffile = new PDFFile(buf);
		previewPanel1.Update(pdffile, 1, true);
	}

	private String getFilePath(String fileName) {
		String newStr = "";
		try {
			//String[] Str = fileName.split(File.separator);
			String[] Str = fileName.split("\\" + File.separator);
			if (Str.length == 0) {
				return null;
			}

			for (int i = 0; i < Str.length - 1; i++) {
				newStr += Str[i] + File.separatorChar;
			}
		} catch (Exception ex) {
			//System.out.println(ex.getMessage());
			outputTextArea.append(ex.toString()+ "\n");
		}
		return newStr;
	}

	public int Notify(String fileName) {
		return Notify(true, fileName);
	}

	/**
	 * 
	 * @param hard If the page will be refreshed then true, otherwise false
	 * @param fileName The file name to be previewed
	 * @return the total number of pages
	 */
	public int Notify(boolean hard, String fileName) {
		if (previewPanel1 != null) {
			try {
				ByteBuffer buf;
				if (hard) { // file needs to be refreshed
					//File file = new File(pdfExt(this.currentFileName));
					//OS kontrolu buraya da eklendi.TG
					String runningOperatingSystem = System.getProperty("os.name");
					String filePath = "";
					if(runningOperatingSystem.contains("Windows")){
						filePath = currentFileName.substring(0, currentFileName.lastIndexOf("\\")) + "\\" + fileName;
					} else if(runningOperatingSystem.contains("Linux")){
						filePath = currentFileName.substring(0, currentFileName.lastIndexOf("/")) + "/" + fileName;
					}
					File file = new File(pdfExt(filePath));
					RandomAccessFile raf = new RandomAccessFile(file, "r");
					FileChannel channel = raf.getChannel();
					buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
					pdffile = new PDFFile(buf);
					raf.close();
					buf.clear();
					channel.close();
				}
				previewPanel1.Update(pdffile, LastPageDisplayed, hard);
				final int retval = pdffile.getNumPages();

				if (hard) {
					if (LastPageDisplayed != 1) {
						prevButton.setEnabled(true);
					}
					if (LastPageDisplayed < retval) {
						nextButton.setEnabled(true);
					}
					if (retval < LastPageDisplayed) {
						LastPageDisplayed = retval;
						nextButton.setEnabled(false);
						previewPanel1.Update(pdffile, LastPageDisplayed, false);
					}
				}
				final int page = LastPageDisplayed;
				SwingUtilities.invokeLater(new Runnable() {

					public void run() {
						pagesTextField.setText(page + "/" + retval);
					}
				});

				return retval;
			} catch (IOException ex) {
				Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
				outputTextArea.append(ex.toString()+"\n");
			}
		}
		return -1;
	}

	/**
	 * 
	 * Preview the generated PDF file of the TEX script on the preview panel 
	 */
	private void btnPreviewActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnPreviewActionPerformed
		// TODO add your handling code here:
		if(Save(false))
		{
			try {
				if (generatePdf("")) {
					DocNumberOfPages = Notify(tempPdfFileName);
				}
			} catch (FileNotFoundException ex) {
				Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
				outputTextArea.append(ex.toString()+"\n");
			} catch (IOException ex) {
				Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
				outputTextArea.append(ex.toString()+"\n");
			}
		}
		else
		{

			JOptionPane.showMessageDialog(null, "The file is not saved. Operation is cancelled!","File Warning",JOptionPane.WARNING_MESSAGE);
		}
	}//GEN-LAST:event_btnPreviewActionPerformed
	
	//TG work on this part.
	private void btnPreviewSelectedTexActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnPreviewActionPerformed
		// TODO add your handling code here:
//			TextEditors editors = new TextEditors();
//			String selectedText = getSelectedText(editors);
//					
//			String previewDocumentContent = "\\documentclass{article}\n\\begin{document}\n"+selectedText+"\n\\end{document}";

			try {
//				if (generatePdf(previewDocumentContent)) {
//					DocNumberOfPages = Notify(tempPdfFileName);
//				}
				if (generatePdfSelectedText()) {
	            	DocNumberOfPages = Notify(tempPdfFileName);
	            }
			} catch (FileNotFoundException ex) {
				Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
				outputTextArea.append(ex.toString()+"\n");
			} catch (IOException ex) {
				Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
				outputTextArea.append(ex.toString()+"\n");
			}			
	}//GEN-LAST:event_btnPreviewActionPerformed

    private boolean generatePdfSelectedText() throws FileNotFoundException, IOException {
        TextEditors ClsTextEditor = new TextEditors();
        int index = tab_Editors.getSelectedIndex();
        JTextPane textPane = ClsTextEditor.GetJTextPane(tab_Editors);
        if (textPane.getSelectedText() == null)
        {
        	outputTextArea.setText("\nNo text selected !!! Please select text to preview\n");
        	return false;
        }
        String filePath = ClsTextEditor.GetRealPath(index);
        String filePathSelected = filePath.substring(0, filePath.length()-4) + "s" + ".tex";
        currentFileName = filePathSelected;
        Process proc = null;
        ProcessBuilder pbuilder = new ProcessBuilder();
        pbuilder.directory(new File(getFilePath(currentFileName)));
        BufferedReader input;
        
        try
        {
        	FileWriter writeFile = new FileWriter(filePathSelected);
        	
        	String CompleteFile = textPane.getText();
        	String CompleteString =  CompleteFile.substring(0,CompleteFile.indexOf("\\begin{document}")+16) + "\n" + textPane.getSelectedText() + "\n" + "\\end{document}";
            writeFile.write(CompleteString);
            writeFile.close();
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null,ex.getMessage(),"File error",JOptionPane.ERROR_MESSAGE);
        }

        if (!new File(currentFileName).exists()) {
        	outputTextArea.setText("\nNothing to preview !!!\n");
            return false;
        }
        try {
        	String runningOperatingSystem = System.getProperty("os.name");
            if (runningOperatingSystem.contains("Linux"))
            {	
            	String[] exLinux = {"pdflatex", "-halt-on-error", "-interaction", "nonstopmode", "-output-directory", getFilePath(currentFileName), currentFileName};
            	pbuilder.command(exLinux);
            }
            else if (runningOperatingSystem.contains("Windows"))
            {
            	String[] exWindows = {MikTexStuff.getMikTexPath() +"pdflatex.exe", "-halt-on-error", "-interaction", "nonstopmode", "-output-directory", getFilePath(currentFileName), currentFileName};
            	pbuilder.command(exWindows);
            }
            
            proc = pbuilder.start();
            String line;

            input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            while ((line = input.readLine()) != null) {
                outputTextArea.setText("[output] " + line + "\n");
            }
            input.close();

            input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
            while ((line = input.readLine()) != null) {
                outputTextArea.setText("[errors] " + line + "\n");
            }
            input.close();
            
            String pathDirectory;
            int indexOfBSlash = currentFileName.lastIndexOf("\\");
            if(indexOfBSlash >= 0)
            {
            	pathDirectory = currentFileName.substring(0, indexOfBSlash);
            }
            //IT : For linux..
            else
            {
            	pathDirectory = getFilePath(currentFileName);
            }
            File oldTempFile;           
            if(indexOfBSlash >= 0)
            {
            	oldTempFile = new File(pathDirectory + "\\" + tempPdfFileName);
            }
            else
            {
            	oldTempFile = new File(getFilePath(currentFileName) + "/" + tempPdfFileName);
            }
            
            
            tempPdfFileName = tempStatic + Integer.toString(tempCounter);
            tempCounter++;

            copyToTempPdf(currentFileName, tempPdfFileName);
            if(oldTempFile.exists()){
                try{
                    oldTempFile.deleteOnExit();
                }
                catch(SecurityException sec){
                    String error = "sec exception";
                }
                catch(Exception exs){
                    String error = exs.getMessage();
                }
                
            }
            int value = proc.waitFor();
            if (value != 0) {
            	outputTextArea.setText("\nNothing to preview !!!\n");
                return false;
            }
            return true;
        } catch (Throwable e) {
            outputTextArea.setText(outputTextArea.getText() + "\npdflatex: command not found " + e.getMessage()+ e.toString());
            return false;
        }
        finally {
            if (proc != null) {
                try {
                    proc.getInputStream().close();
                    proc.getOutputStream().close();
                    proc.getErrorStream().close();
                    proc.destroy();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
	private void prevButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_prevButtonActionPerformed
		// TODO add your handling code here:
		if (LastPageDisplayed > 1) {
			LastPageDisplayed--;
			Notify(false, tempPdfFileName);
			if (LastPageDisplayed == 1) {
				prevButton.setEnabled(false);
			}
			nextButton.setEnabled(true);
		}
	}//GEN-LAST:event_prevButtonActionPerformed

	private void nextButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
		// TODO add your handling code here:
		if (LastPageDisplayed < DocNumberOfPages) {
			LastPageDisplayed++;
			Notify(false, tempPdfFileName);
			prevButton.setEnabled(true);
			if (LastPageDisplayed == DocNumberOfPages) {
				nextButton.setEnabled(false);
			}
		}
	}//GEN-LAST:event_nextButtonActionPerformed

	private void createToolbarBtnActionPerformed(ActionEvent evt) {//GEN-FIRST:event_createToolbarBtnActionPerformed
		JDialog dia = new JDialog();
		DynamicToolbarWizard wizard = new DynamicToolbarWizard(dia);
		dia.getContentPane().add(wizard);

		dia.setTitle("Toolbar Wizard");
		dia.setSize(600, 450);
		//dialog.setLocation((int)mainPanel.getLocation().getX() + 200, (int)mainPanel.getLocation().getY() + 200);
		dia.setResizable(true);
		dia.setModal(true);
		dia.setVisible(true);

		while(wizard.hasFocus()){
			//wait until button created
		}

		if(wizard.getToolbar() != null){
			//int toolbarCount = ToolBarHandler.getHandler().getToolbars().size();
			ToolBarHandler tbh = ToolBarHandler.getHandler();
			tbh.getToolbars().add(wizard.getToolbar());
			tbh.serializeToolBars();
			if(tbh.getError().equals("")== false)
			{
				outputTextArea.append(tbh.getError()+"\n");
			}
		}
	}//GEN-LAST:event_createToolbarBtnActionPerformed

	/*
	 * Dyanmic LaTeX Toolbar Buttons Action Handler Method
	 * THIS METHOD IS FOR v1.1
	 * */
	public static void PerformLatexButtonAction(LatexButton btn) {
		try {
			TextEditors editors = new TextEditors();
			String expression = btn.getExpressionTemplate();
			if (getSelectedText(editors).isEmpty()) {
				replaceSelectedText(editors, expression);
			} else {
				String prefix = btn.getPrefix();
				String suffix = btn.getSuffix();
				String selected = getSelectedText(editors);
				if(prefix == null)
					prefix = "";

				if(suffix == null)
					suffix = "";

				replaceSelectedText(editors, prefix + selected + suffix);
			}
		} catch (Exception ex) {
			outputTextArea.append("Error: " + ex.getMessage()+ "\n");
		}
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				try {                	
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				} catch (ClassNotFoundException ex) {
					Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
					outputTextArea.append(ex.toString());
				} catch (InstantiationException ex) {
					Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
					outputTextArea.append(ex.toString());
				} catch (IllegalAccessException ex) {
					Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
					outputTextArea.append(ex.toString());
				} catch (UnsupportedLookAndFeelException ex) {
					Logger.getLogger(ExeditorLatexEditor.class.getName()).log(Level.SEVERE, null, ex);
					outputTextArea.append(ex.toString());
				}
				exeditorLatexEditor = new ExeditorLatexEditor();
				exeditorLatexEditor.setVisible(true); 			
			}
		});
	}
	
	public JComboBox getNavigationComboBox() {
		return navigationComboBox;
	}
	
	public JTextPane getTextEditor()
	{
		return new TextEditors().GetJTextPaneAt(this.tab_Editors, this.tab_Editors.getSelectedIndex());
	}
	


	public String commandResult;
	private CustomizeForm customizeForm = null;
	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JMenuItem findAndReplaceMenuItem;
	private javax.swing.JMenuItem gotoLineMenuItem;
	private JMenuItem setTemplateMenuItem;
	private javax.swing.JMenuItem wordCountMenuItem;
	private JMenuItem setMikTexPathMenuItem;  //TG
	private javax.swing.JButton alignCenterButton;
	private javax.swing.JButton alignLeftButton;
	private javax.swing.JButton alignRightButton;
	private javax.swing.JButton boldButton;
	private javax.swing.JButton btnPreview;
	private JButton btnPreviewSelectedTex;
	private javax.swing.JButton commentInBtn;
	private javax.swing.JButton commentOutBtn;
	private javax.swing.JButton convertToPdfButton;
	private javax.swing.JButton copyButton;
	private javax.swing.JMenuItem create;
	private javax.swing.JButton createToolbarBtn;
	private javax.swing.JMenuItem customize;
	private javax.swing.JDialog customizeDialog;
	private javax.swing.JMenuItem customizeMenuItem;
	private javax.swing.JButton cutButton;
	private javax.swing.JMenuItem editMenuCopyItem;
	private javax.swing.JMenuItem editMenuCutItem;
	private javax.swing.JMenuItem editMenuItemRedo;
	private javax.swing.JMenuItem editMenuItemUndo;
	private javax.swing.JMenuItem editMenuPasteItem;
	private javax.swing.JMenuItem fileMenuCloseItem;
	private javax.swing.JMenuItem fileMenuExit;
	private javax.swing.JMenu fileMenuExitItem;
	private javax.swing.JMenuItem fileMenuNewItem;
	private javax.swing.JMenuItem fileMenuOpen;
	private javax.swing.JMenuItem fileMenuSave;
	private javax.swing.JMenuItem fileMenuSaveAs;
	private javax.swing.JLabel hiddenLabel;
	private javax.swing.JButton italicButton;
	private javax.swing.JComboBox jComboBoxCovertTo;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JMenu toolBarMenu;
	private javax.swing.JMenu editMenu;
	private javax.swing.JMenuBar mainMenuBar;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JToolBar.Separator jSeparator1;
	private javax.swing.JToolBar.Separator jSeparator2;
	private javax.swing.JToolBar.Separator jSeparator3;
	private javax.swing.JSeparator jSeparator4;
	private javax.swing.JSeparator jSeparator5;
	private javax.swing.JToolBar.Separator jSeparator6;
	private javax.swing.JToolBar.Separator jSeparator7;
	private javax.swing.JSplitPane jSplitPane1;
	private javax.swing.JToolBar jToolBar1;
	private javax.swing.JButton newButton;
	private javax.swing.JButton nextButton;
	private javax.swing.JButton openButton;
	private javax.swing.JLabel outputLabel;
	private static javax.swing.JTextArea outputTextArea;
	private javax.swing.JTextField pagesTextField;
	private javax.swing.JButton pasteButton;
	private javax.swing.JButton prevButton;
	private com.meraklisina.latexeditor.PreviewPanel previewPanel1;
	private javax.swing.JButton saveButton;
	public static javax.swing.JTabbedPane tab_Editors;
	private JComboBox navigationComboBox;
	private javax.swing.JPopupMenu toolbarContextMenu;
	private javax.swing.JPanel toolbarPanel;
	//private javax.swing.JMenuItem importToolbar;
	//private javax.swing.JMenuItem exportToolbar;
	
	private javax.swing.JButton underlineButton;
	private javax.swing.JMenu helpMenu;
	private javax.swing.JMenuItem about;
	private javax.swing.JMenuItem help;
	private javax.swing.JMenu templateMenu; //AE
	private javax.swing.JMenuItem tlist;  //AE
	private javax.swing.JDialog tlistDialog;
	// End of variables declaration//GEN-END:variables
}
